﻿using AutoPoco.Engine;

namespace Autopoco.Contrib.DataSources
{
    public class SequentialIntSource : AbstractRelatedDataSource<int>
    {
        private int _current;
        public SequentialIntSource(int current)
        {
            _current = current;
        }
        public SequentialIntSource()
            : this(1)
        {
        }
        public override int Next(IGenerationSession session)
        {
            return _current++;
        }

        public override void Setup(RelationContext context)
        {
            if (context.Dictionary.ContainsKey(DatasourceConstant.ResetLevels) &&
                context.Dictionary[DatasourceConstant.ResetLevels].ToString() == DatasourceConstant.True)
                _current = 1;
        }
    }
}